{extend name="layout/detail" /}
{block name="content"}
<link rel="stylesheet" href="__ADMIN__/css/formSelects-v4.css"/>
<div class="space-10"></div>
<div class="td-content-wrap p20">
    <div class="td-content-header">
        <h1>用户管理</h1>
    </div>
    <hr>
    <div class="panel no-border">
        <div id="adv_search">
            <form id="form_adv_search" class="layui-form" method="post">
                <div class="layui-input-inline">
                    <input class="layui-input" name="keyword" placeholder="员工编号/花名/手机号" />
                </div>
                
                <div class="layui-input-inline w6">
                    <label>部门：</label>
                </div>
                <div class="layui-input-inline">
                    <select name="dept_no" >
                        <option></option>
                        {:fill_option($department_list)}
                    </select>
                </div>

                <div class="layui-input-inline w6">
                    <label>状态：</label>
                </div>
                <div class="layui-input-inline">
                    <select id="eq_is_valid" name="eq_is_valid" lay-filter="is_valid">
                        <option value="">请选择</option>
                        <option value="1">启用</option>
                        <option value="0">禁用</option>
                    </select>
                </div>

                <div class="layui-input-inline w6">
                    <a class="layui-btn" onclick="adv_search()"><i class="fa fa-search"></i>搜索</a>
                </div>
            </form>
        </div>
        <span class="mid"></span>
        <a class="layui-btn" onclick="add();">添加</a>
    </div>
    <table id="data_table" lay-filter="data_table"></table>
</div>
{/block}

{block name="script"}
<script type="text/html" id="tool_bar">
    <input data-id="{{d.id}}" type="checkbox" name="is_valid" value="1" lay-skin="switch" lay-text="启用|禁用"
           lay-filter="is_valid" {{ d.is_valid== 1 ? 'checked' : '' }}>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/html" id="sort">
    <span class="handle" data-id="{{d.id}}" data-sort="{{d.sort}}"><i class="iconfont td-tuodong pointer"></i></span>
</script>
<script>
    layui.use(['element', 'data_table'], function () {
        let $ = layui.jquery;
        let data_table = layui.data_table;

        // 记录返回地址
        set_return_url(null);

        // 页面用到方法
        let fn = {
            add: function (data) {
                popup_open('{:url("add")}', 720, 640);
            },
            read: function (data) {
                popup_open('{:url("read")}?id=' + data.id, 720, 640);
            },
            edit: function (data) {
                popup_open('{:url("edit")}?id=' + data.id, 720, 640);
            },
            del: function (data) {
                layer.msg('确定要删除吗?', {
                    time: 0,
                    btn: ['确定', '取消'],
                    yes: function (index) {
                        var vars = 'id=' + data.id;
                        $.get("{:url('del')}", vars, function (res) {
                            if (res.code) {
                                layer.msg(res.msg, {
                                    time: 1200
                                }, function () {
                                    location.reload(true);
                                });
                            } else {
                                layer.msg(res.msg, {time: 1200});
                            }
                        });
                    },
                    no: function (index) {
                        layer.close(index);
                    }
                });
            },
        };
        win_exp(fn);

        let cols = [[
            {
                field: 'staff_no',
                title: '员工编号',
                align: 'center',
                width: 150,
            },
            {
                field: 'nickname',
                title: '员工花名',
            },
            {
                field: 'real_name',
                title: '员工姓名',
            },
            {
                field: 'username',
                title: '手机号',
            },
            {
                field: 'dept_name',
                title: '所属部门',
            },
            {
                field: 'entry_time',
                title: '入职时间',
            },
            {
                toolbar: '#tool_bar',
                title: '操作',
                fixed: 'right',
            }]];

        data_table.config.cols = cols;
        data_table.config.limit = 50;
        data_table.render();

    });
</script>
{/block}